package com.pearl.shardingsphere.rw.algorithm;

import cn.hutool.core.util.RandomUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;

import java.util.Collection;

/**
 * @author TD
 * @version 1.0
 * @date 2024/1/25
 */
@Slf4j
public class RandomStandardShardingAlgorithm implements StandardShardingAlgorithm<Long> {


    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Long> preciseShardingValue) {
        int randomInt = RandomUtil.randomInt(0, 6);
        log.info("随机数：" + randomInt);
        return "t_order_" + randomInt;
    }

    @Override
    public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Long> rangeShardingValue) {
        return null;
    }
}
